***Curtis RESTAT
***This is the data prep do file used in Table 5

drop if year>2008
gen post=1 if inlist(year,2005,2006,2007,2008)
replace post=1 if year==2004 & inlist(quarter,3,4)
replace post=1 if year==2004 & inlist(quarter,1,2) & inlist(state,"09","10","11","23","24","33","34","36","42")
replace post=1 if year==2004 & inlist(quarter,1,2) & inlist(state,"44","50")
replace post=1 if year==2003 & inlist(quarter,3,4) & inlist(state,"09","10","11","23","24","33","34","36","42")
replace post=1 if year==2003 & inlist(quarter,3,4) & inlist(state,"44","50")
gen NBP=1 if inlist(state,"01","09","10","11","17","18","19","21","34")
replace NBP=1 if inlist(state,"23","24","25","26","27","33","36","37","38")
replace NBP=1 if inlist(state,"39","42","44","45","47","50","51","54","55")
replace NBP=0 if NBP==.
replace post=0 if post==.
tostring naics3,replace
merge m:m naics3 using ind3_table5
keep if _m==3
drop _m

tostring NBP,gen(NBPstr)
gen NBPind=NBPstr+naics3
drop if state=="29"
gen postxNBP=post*NBP
gen postxint=post*en_int
gen intxNBP=en_int*NBP
gen postxNBPxint=post*NBP*en_int


gen highint=0
replace highint=1 if en_int>.03
gen postxhigh=post*highint
gen NBPxhigh=NBP*highint
gen postxNBPxhigh=post*NBP*highint


gen fulltemp=1 if year==2000 & quarter==2
egen statetemp=max(fulltemp),by(state)
keep if statetemp==1



tostring year quarter,replace
gen yqtr=year+"Q"+quarter
gen ind_qtr=naics3+yqtr
gen state_qtr=state+yqtr
gen state_ind=state+"_"+naics3 
encode ind_qtr, gen(ind_qtrf)
qui tab state_ind,gen(STinddum)
qui tab yqtr,gen(qtrdum)
qui tab state,gen(statedum)

gen tempend=emp if year=="2000" & quarter=="2"
egen emp_weight=max(tempend),by(state_ind)
gen temp=emps if year=="2004" & quarter=="2"
egen emp_base=max(temp),by(state_ind)

so yqtr
encode yqtr, gen(trend)

foreach z of varlist statedum1-statedum40 {
gen trend`z'=`z'*trend
drop `z'
}

foreach x of varlist qtrdum1-qtrdum44 {
gen NBPxhighx`x' = NBPxhigh*`x'
gen intxNBPx`x' = intxNBP*`x'
}

order intxNBPx*
tab naics3,gen(ind)

forvalues i = 1(1)21 {
  qui gen eindtrend`i' = ind`i'*NBP*trend
 }
forvalues i = 1(1)21 {
  qui gen windtrend`i' = ind`i'*((NBP-1)^2)*trend
 }

drop if inlist(semps,-1,-2)
drop if inlist(shiras,-1,-2)
drop if inlist(seps,-1,-2)
drop if inlist(sfrmjbgns,-1,-2)
drop if inlist(sfrmjblss,-1,-2) 

so state naics3 yqtr
merge 1:1 state naics3 yqtr using allemp_mergeprep_table5
drop _m
drop if year=="2008" & quarter=="4"

